import GCJ_CLASS_TYPE = require('./../../common/GCJ_CLASS_TYPE');
import Serializer = require('./../base/Serializer');
import ObjPosition=require('./../base/ObjPosition');
import SJGReplaceItemBase = require('./SJGReplaceItemBase');
import CompoundPath = require('./../../common/graph/CompoundPath');
import CommonModel = require('./../../common/model/CommonModel');



var CONFIG=require('../../../../common/config');
export  = SJGReplaceItemGraph;

/**
 *
 * @author 
 *
 */
class SJGReplaceItemGraph extends SJGReplaceItemBase{

    public gt: number = 0; // 见数据库的graph_type
    public cp: CompoundPath = null; // 图形路径
    
    public constructor(g?) {
        super(g);

        this.ct = GCJ_CLASS_TYPE.CLASS_TYPE_SJGReplaceItemGraph;
        this.type=SJGReplaceItemBase.TYPE_GRAPH;
    }
    
    // 从json对象(注意不是json字符串)中解析
    public fromJson(jsonObj,versionId) {
        super.fromJson(jsonObj,versionId);

        this.gt = jsonObj.gt;
        
        if(jsonObj.hasOwnProperty("cp") && jsonObj.cp != null) {
            this.cp = new CompoundPath();
            this.cp.fromJson(jsonObj.cp,versionId);
        }
    }
    
    // 转成json字符串
    public toJson(): string {
        // 去掉父json字符串的头尾
        var superJson = super.toJson();
        superJson = superJson.substr(1,superJson.length - 2);

        var ret = '{';
        ret += superJson;
        
        // gt
        ret += ',';
        ret += '"gt":';
        ret += this.gt;
        
        // cp
        if(this.cp != null) {
            ret += ',';
            ret += '"cp":';
            ret += this.cp.toJson();
        }

        ret += '}';
        return ret;
    }
    
    // 获取对象名称
    public getObjetName(): string {
        return "图形";
    }

    
}//SJG_MARK_END-------------------------